import { getGoodsSearch } from '../../service/goods';
import { debounce } from '../../utils/util';

Page({
  data: {
    goodsList: [],
    inputVal: ''
  },
  handleInputSearch: function (e) {
    let query = e.detail.value;
    if (!query.trim() || query === '') {
      this.setData({goodsList: []})
      return;
    }
    let x = debounce(this.getGoodsList);
    x(query);

  },
  getGoodsList: async function(query) {
    let res = await getGoodsSearch(query);
    this.setData({
      goodsList: res.data.message
    })
  },
  handleCancel() {
    this.setData({
      goodsList: [],
      inputVal: ''
    })
  }
})